package com.ming.mingbase.base.dao;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.orm.hibernate4.HibernateTemplate;

import com.ming.mingbase.base.exeption.BaseException;
import com.ming.mingbase.base.util.Page;



public interface IBaseDao {
	/**
	 * 添加
	 * 
	 * @param entity
	 * @return
	 * @throws BaseException
	 */
	public <T> boolean add(T entity) throws BaseException;

	/**
	 * 添加并返回int的id
	 * 
	 * @param entity
	 * @return
	 * @throws BaseException
	 */
	public <T> Integer addAndGetIdInteger(T entity) throws BaseException;

	/**
	 * 添加并返回string的id
	 * 
	 * @param entity
	 * @return
	 * @throws BaseException
	 */
	public <T> String addAndGetIdString(T entity) throws BaseException;

	/**
	 * 删除（必须有id）
	 * 
	 * @param entity
	 * @return
	 * @throws BaseException
	 */
	public <T> boolean delete(T entity) throws BaseException;
	/**
	 * 根据sql删除
	 * 
	 * @param sql
	 * @return
	 * @throws BaseException
	 */
	public boolean delete(String sql) throws BaseException;
	/**
	 * 批量删除
	 * @param sql
	 * @param ids
	 * @throws BaseException
	 */
	public void batchDel(String sql,String ids[])throws BaseException;

	/**
	 * 执行（非查询）
	 * 
	 * @param hql
	 * @return
	 * @throws Exception
	 */
	public int executeBySql(String sql) throws BaseException;

	/**
	 * 更新
	 * 
	 * @param entity
	 * @return
	 * @throws BaseException
	 */
	public <T> boolean edit(T entity) throws BaseException;

	/**
	 * 根据sql更新
	 * 
	 * @param sql
	 * @return
	 * @throws BaseException
	 */
	public int editBySql(String sql) throws BaseException;

	/**
	 * 根据id查询
	 * 
	 * @param c
	 * @param id
	 * @return
	 * @throws BaseException
	 */
	public <T> T getById(Class<T> entity, Serializable id) throws BaseException;

	/**
	 * 根据id查询
	 * 
	 * @param sql
	 * @return
	 * @throws BaseException
	 */
	public <T> T getBySql(Class<T> t,String sql) throws BaseException;
	/**
	 * 根据条件查询对象
	 * @param entity
	 * @param sql
	 * @param searchValue
	 * @return
	 * @throws BaseException
	 */
	public <T> T getBySql(Class<T> entity, String sql,Map<String, Object> searchValue) throws BaseException;
	/**
	 * 根据条件查询对象(Vo)
	 * @param entity
	 * @param sql
	 * @param searchValue
	 * @return
	 * @throws BaseException
	 */
	public <T> T getBySqlVO(Class<T> entity, String sql,Map<String, Object> searchValue) throws BaseException;
	/**
	 * 根据id查询
	 * 
	 * @param entity
	 * @param id
	 * @return
	 * @throws BaseException
	 */

	public <T> T getById(Class<T> entity, String id) throws BaseException;

	/**
	 * 根据id查询
	 * 
	 * @param entity
	 * @param id
	 * @return
	 * @throws BaseException
	 */
	public <T> T getById(Class<T> entity, Integer id) throws BaseException;
	/**
	 * 根据条件查询
	 * 
	 * @param entity
	 * @param sql
	 * @return
	 * @throws Exception
	 */
	public <T> List<T> findBySql(Class<T> entity, String sql) throws BaseException;
	/**
	 * 根据条件查询
	 * @param entity
	 * @param sql
	 * @param searchValue
	 * @return
	 * @throws BaseException
	 */
	public <T> List<T> findBySql(Class<T> entity, String sql, Map<String, Object> searchValue) throws BaseException;
	/**
	 * 根据条件查询
	 * 
	 * @param entity
	 * @return
	 * @throws Exception
	 */
	public <T> List<T> getList(Class<T> entity) throws BaseException;

	/**
	 * 根据条件查询
	 * 
	 * @param sql
	 * @param searchValue
	 * @return
	 * @throws Exception
	 */
	public <T> List<T> getList(Class<T> entity,String sql, Map<String, Object> searchValue) throws BaseException;

	/**
	 * 分页查询
	 * 
	 * @param querySql
	 * @param queryCountSql
	 * @param searchValue
	 * @param page
	 * @return
	 * @throws Exception
	 */
	public <T> Page getByPage(Class<T> entity,String querySql, String queryCountSql, Map<String, Object> searchValue, Page page) throws BaseException;
	/**
	 * 分页查询VO
	 * 
	 * @param querySql
	 * @param queryCountSql
	 * @param searchValue
	 * @param page
	 * @return
	 * @throws Exception
	 */
	public <T> Page getByPageVO(Class<T> entity,String querySql, String queryCountSql, Map<String, Object> searchValue, Page page) throws BaseException;
	/**
	 * 预设Sql
	 * @param sql
	 * @return
	 * @throws BaseException
	 */
	public SQLQuery PrepareSql(String sql)throws BaseException;
	/**
	 * 设置参数
	 * @param key
	 * @param vlaue
	 * @throws BaseException
	 */
	public void preValue(String key,Object vlaue)throws BaseException;
	/**
	 * 执行sql
	 * @throws BaseException
	 */
	public void executeSql()throws BaseException;
	/**
	 * 获取session
	 * 
	 * @return
	 */
	public Session session();

	/**
	 * 获取HibernateTemplate
	 * 
	 * @return
	 */
	public HibernateTemplate getTemplate();
}
